package com.godpaper.as9.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.godpaper.as9.bussiness.delegates.ClassDelegate;
	import com.godpaper.as9.events.GetClassListEvent;
	import com.godpaper.as9.model.ClassModelLocator;
	import com.godpaper.as9.vo.ClassVO;
	
	import mx.rpc.IResponder;

	public class GetClassListCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:ClassDelegate;
		private var getClassListEvent:GetClassListEvent;
		private var classModel:ClassModelLocator = ClassModelLocator.getInstance();
		public function GetClassListCommand()
		{
			super();
			delegate = new ClassDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			getClassListEvent = GetClassListEvent(event);
			delegate.read(null);
		}
		
		override public function result(data:Object):void
		{
			classModel.classList.removeAll();
			for(var i:int=0;i<data.result.length;i++)
			{
				var vo:ClassVO = new ClassVO();
				vo.capcity = data.result[i].capcity;
				vo.cno = data.result[i].cno;
				vo.created_time = data.result[i].created_time;
				vo.name = data.result[i].name;
				vo.thumbnail = data.result[i].thumbnail;
				vo.user_registed = data.result[i].user_registed;
				
				classModel.classList.addItem(vo);
			}
			classModel.classList.refresh();
		}
		
		
	}
}